package com.dao.imp;

import com.entity.ChildType;
import com.entity.GoodStatus;
import com.util.DBConn;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Mathison
 * @Title: FindCollectStatus
 * @Package: com.dao.imp
 * @Description: TODO
 * @date 2021/11/25 17:15
 **/
public class FindCollectStatus {
    public static GoodStatus getGoodStatus(String sql){
        GoodStatus goodStatus = new GoodStatus();
        try{
            DBConn.init();
            ResultSet resultSet = DBConn.selectSql(sql);
            while (resultSet.next()){
                goodStatus.setUser_id(resultSet.getInt("user_id"));
                goodStatus.setGood_id(resultSet.getInt("good_id"));
                goodStatus.setStatus(resultSet.getBoolean("status"));
            }
//            DBConn.closeConn();
        }catch (SQLException e){
            e.printStackTrace();
        }
        return goodStatus;
    }

    public static List<GoodStatus> findAllGollection(String sql){
        List<GoodStatus> colleList = new ArrayList<>();
        try{
            DBConn.init();
            ResultSet resultSet = DBConn.selectSql(sql);
            while (resultSet.next()){
                GoodStatus goodStatus = new GoodStatus();
                goodStatus.setUser_id(resultSet.getInt("user_id"));
                goodStatus.setGood_id(resultSet.getInt("good_id"));
                goodStatus.setStatus(resultSet.getBoolean("status"));

                colleList.add(goodStatus);
            }
//            DBConn.closeConn();
        }catch (SQLException e){
            e.printStackTrace();
        }
        return colleList;
    }

    public static int isInit(String sql){
        int result=0;
        DBConn.init();
        result = DBConn.countSql(sql);
        return  result;
    }
}
